﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            ImportCarJP jp = new ImportCarJP();
            jp.ExecuteBaseClear();

            //new ProcessCarInfo().Excute();
            var APP_ID = "16103552";
            var API_KEY = "b5t6VkF4ELhl70mGOVYV78Hh";
            var SECRET_KEY = "gscWgXDtizWc05rY6eZWoA6XNhHQCkDq";

            var client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);
            client.Timeout = 60000;

            StringBuilder sb = new StringBuilder();
            DirectoryInfo dir = new DirectoryInfo("E:\\img");
            var files= dir.GetFiles("*.jpg");
            //foreach (var item in files)
            //{
            //    var image = File.ReadAllBytes(item.FullName);

            //    // 调用通用文字识别, 图片参数为本地图片，可能会抛出网络等异常，请使用try/catch捕获
            //    var result = client.AccurateBasic(image);
            //    sb.AppendLine(item.Name + ":" + result);
            //}
            //string rt = sb.ToString();  
            //百度AI 9个识别1个

            foreach (var item in files)
            {
                sb.AppendLine(item.Name + ":" + FileToBase64(item.FullName));
            }
            string rt = sb.ToString();
            //聚合数据9个对6个
        }


        /// <summary>
        /// 文件读取成base64
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        protected static string FileToBase64(string path)
        {
            byte[] inArray = File.ReadAllBytes(path);
            string str = Convert.ToBase64String(inArray);
            return str;
        }
    }
}
